import axios, { InternalAxiosRequestConfig, AxiosResponse } from 'axios';
import { useUserStoreHook } from '@/store/modules/user';

// 创建 axios 实例
const service = axios.create({
      baseURL: "",
      timeout: 50000,
      headers: { 'Content-Type': 'application/json;charset=utf-8' }
});

service.interceptors.request.use(
      (config: InternalAxiosRequestConfig) => {
            const userStore = useUserStoreHook();
            if (localStorage.getItem("token2")) {
              config.headers.Authorization = localStorage.getItem("token2");
            }
            return config;
      },
      (error: any) => {
            return Promise.reject(error);
      }
);
 
// axios.defaults.baseURL = 'http://localhost:3000'
 
export const addUser = (data:any) => service.post('/api/user/addUser',data).then(res => res.data)
 
export const getList = (data:any) => service.get(`/api/user?time=${new Date().getTime()}`,{params:data}).then(res => res.data)
 
export const delUser = (data:any) => service.delete(`/api/user/${data.id}`).then(res => res.data)
 
export const updateUser = (data:any) => service.patch(`/api/user/${data.id}`,data).then(res => res.data)

export const addTags = (data:any) => service.post(`/api/user/add/tags?time=${new Date().getTime()}`,data).then(res => res.data)

export const getTags = (data:any) => service.get(`/api/user/get/tags?time=${new Date().getTime()}`,{params:data}).then(res => res.data)

export const getCaptchaApi = (data:any) => service.get(`/api/user/code?time=${new Date().getTime()}`,{params:data}).then(res => res.data)

export const loginTest = (data:any) => service.post(`/api/user/login?time=${new Date().getTime()}`,data).then(res => res.data)

export const registerTest = (data:any) => service.post(`/api/user/register?time=${new Date().getTime()}`,data).then(res => res.data)